﻿
''' <summary>
''' GoogleDesktopEventFactory
''' </summary>
Public Class [Event]
    Implements IDisposable


    Dim [event] As Object
    Dim _type As EventTypes
#Region " New "

    '''' <summary>
    '''' Create Event
    '''' </summary>
    '''' <param name="id">The component's GUID or ProgID.</param>
    '''' <param name="schema_name"></param>
    '''' <remarks></remarks>
    'Friend Sub New(ByVal id As String, ByVal schema_name As String)
    '    MyClass.New(id, schema_name, EventTypes.Event2)
    'End Sub

    ''' <summary>
    '''  Create Event
    ''' </summary>
    ''' <param name="id">The component's GUID or ProgID.</param>
    ''' <param name="schema_name"></param>
    ''' <param name="eventType">event or event2</param>
    ''' <remarks></remarks>
    Friend Sub New(ByVal id As String, ByVal schema_name As String, ByVal eventType As EventTypes)
        Dim gd As New GoogleDesktop
        Me.event = gd.CreateEvent(id, schema_name)
        Me._type = eventType

    End Sub

    ''' <summary>
    '''  Create Event
    ''' </summary>
    ''' <param name="id">The component's GUID or ProgID.</param>
    ''' <param name="schema_name"></param>
    ''' <param name="eventType">event or event2</param>
    ''' <remarks></remarks>
    Friend Sub New(ByVal id As String, ByVal schema_name As String, ByVal eventType As EventTypes, ByVal eventfactory As Object)

        Dim gd As GoogleDesktop = CType(eventfactory, GoogleDesktop)
        Me.event = gd.CreateEvent(id, schema_name)
        Me._type = eventType

    End Sub

#End Region

    Public ReadOnly Property Type() As EventTypes
        Get
            Return _type
        End Get
    End Property

    Private ReadOnly Property GetEvent() As IGoogleDesktopEvent
        Get
            Return DirectCast(Me.event, IGoogleDesktopEvent)
        End Get
    End Property
    Private ReadOnly Property GetEvent2() As IGoogleDesktopEvent2
        Get
            Return DirectCast(Me.event, IGoogleDesktopEvent2)
        End Get
    End Property

    '''' <summary>
    '''' CreateEvent
    '''' </summary>
    'Public Shared Sub Create()

    'End Sub

    ''' <summary>
    ''' Send
    ''' </summary>
    Public Sub Send(ByVal eventflag As EventFlags)
        Try
            Select Case Me._type
                Case EventTypes.Event
                    GetEvent.Send(eventflag)
                Case EventTypes.Event2
                    GetEvent2.Send(eventflag)
            End Select
        Catch ex As Exception When LogException(ex)
        Catch ex As COMException
            GDException(ex)
        Catch ex As Exception
            Throw
        End Try
    End Sub


    Friend Sub AddProperty(ByVal property_name As String, ByVal property_value As Object)



        Try
            Select Case Me._type
                Case EventTypes.Event

                    GetEvent.AddProperty(property_name, property_value)

                Case EventTypes.Event2

                    GetEvent2.AddProperty(property_name, property_value)
            End Select

        Catch ex As Exception When LogException(ex)
        Catch ex As COMException
            GDException(ex)
        Catch ex As Exception
            Throw
        End Try

    End Sub




    Private disposedValue As Boolean = False        ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then

            End If

            Me.event = Nothing
        End If
        Me.disposedValue = True
    End Sub

#Region " IDisposable Support "
    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class

'Public Enum EventFlags

'    EventFlagContextual = 2
'    EventFlagDuplicate = &H4000
'    EventFlagHistorical = &H10
'    EventFlagIndexable = 1
'    EventFlagReplace = &H2000

'End Enum




Public Enum EventTypes
    [Event]
    Event2
End Enum